package basic.study.leetcode;

import java.util.HashMap;

/**
 * @ClassName Mid3
 * @Description
 * @Company inspur
 * @Author Kevin
 * @Date 2020/6/16 12:13
 * @Version 1.0
 */
public class Mid3 {
    class Solution {
        public int lengthOfLongestSubstring(String s) {
            HashMap<Character, Integer> map = new HashMap<>();
            int ans = 0;
            for (int i = 0, j = 0; j < s.length(); j++) {
                if (map.containsKey(s.charAt(j))) {
                    i = Math.max(i, map.get(s.charAt(j)));
                }
                ans = Math.max(ans, j - i + 1);
                map.put(s.charAt(j), j+1);
            }
            return ans;
        }
    }
}
